import os
import sys
import py2exe
import glob
from distutils.core import setup

# go to root directory (cd ..)
root = os.path.split(os.getcwd())[0]
sys.path.append(root)
sys.path.append(os.path.join(root, 'pypk'))
os.chdir(root)

__pname__ = 'pypk'
__ver__ = 'v0.2'

if os.name not in ['nt', 'ce']:
    print "This script is only for use on Win32."
    sys.exit()

      # console executable (== knockd.py)
setup(console=[
        {"script": "pypk/knockd.py",
         "dest_base": "knockd",
         "icon_resources": [(1, "win32compile\\icon.ico")]
         },
        
      # console executable (== knocker.py)        
        {"script": "pypk/knocker.py",
         "dest_base": "knocker",
         "icon_resources": [(1, "win32compile\\icon.ico")]
         }        
        ],     

      # background executable (== knockd.pyw)
      windows=[
        {"script": "pypk/knockd.py",
         "dest_base": "knockdw",
         "icon_resources": [(1, "win32compile\\icon.ico")]
         }
        ],

      # shared library name (default: 'library.zip')
      zipfile="library.zip",

      # opts
      options={
          "py2exe": {
              "dist_dir": "[w32-bin]-%s_%s" %(__pname__, __ver__),
              "optimize": 1,
              "ignores": "syslog",
              "includes": ["encodings", "encodings.*"]
              }
          },

      # files
      data_files=[
          ("",["LICENSE",
               "README",
               "TODO",
               "HISTORY",
               "INSTALL",               
               "win32compile\\knockd.conf",
               "win32compile\\installer.nsi"]),
          ("doc", glob.glob("doc\\*txt")),
          ("doc", glob.glob("doc\\*html")),
          ("doc\\images", glob.glob("doc\\images\\*")),
          ],
      )

# delete "build" directory generated by py2exe
try:
    os.system("rmdir /S /Q build")
except:
    pass

